#include "Callbacks.h"
#include "Bullet.h"
#include "Battery.h"

namespace BulletScript
{

using namespace bs;

// ----------------------------------------------------------------------------
UserTypeBase* bullet_emitAngle(float x, float y, float angle, const float* args, void* userObj)
{
	Battery* battery = static_cast<Battery*>(userObj);
	return battery->EmitAngle(x, y, angle, args);
}
// ----------------------------------------------------------------------------
UserTypeBase* bullet_emitTarget(float x, float y, float angle, const float* args, void* userObj)
{
	Battery* battery = static_cast<Battery*>(userObj);
	return battery->EmitTarget(x, y, angle, args);
}
// ----------------------------------------------------------------------------
void bullet_kill(UserTypeBase* object, void* userObj)
{
	Battery* battery = static_cast<Battery*>(userObj);
	battery->KillBullet(object);
}
// ----------------------------------------------------------------------------
void bullet_setX(UserTypeBase* object, float value)
{
	Bullet* b = static_cast<Bullet*>(object);
	b->x = value;
}
// ----------------------------------------------------------------------------
float bullet_getX(UserTypeBase* object)
{
	Bullet* b = static_cast<Bullet*>(object);
	return b->x;
}
// ----------------------------------------------------------------------------
void bullet_setY(UserTypeBase* object, float value)
{
	Bullet* b = static_cast<Bullet*>(object);
	b->y = value;
}
// ----------------------------------------------------------------------------
float bullet_getY(UserTypeBase* object)
{
	Bullet* b = static_cast<Bullet*>(object);
	return b->y;
}
// ----------------------------------------------------------------------------
void bullet_setAngle(UserTypeBase* object, float value)
{
	Bullet* b = static_cast<Bullet*>(object);

	b->angle = value;

	if (value < 0.0f)
		value += 360.0f;

	b->vx = sin(value * 3.14159 / 180.0) * b->speed;
	b->vy = cos(value * 3.14159 / 180.0) * b->speed;
}
// ----------------------------------------------------------------------------
float bullet_getAngle(UserTypeBase* object)
{
	Bullet* b = static_cast<Bullet*>(object);
	return b->angle;
}
// ----------------------------------------------------------------------------
void bullet_setSpeed(UserTypeBase* object, float value)
{
	Bullet* b = static_cast<Bullet*>(object);

	b->speed = value;

	float angle = b->angle;
	if (angle < 0.0f)
		angle += 360.0f;

	b->vx = sin(angle * 3.14159 / 180.0) * value;
	b->vy = cos(angle * 3.14159 / 180.0) * value;
}
// ----------------------------------------------------------------------------
float bullet_getSpeed(UserTypeBase* object)
{
	Bullet* b = static_cast<Bullet*>(object);
	return b->speed;
}
// ----------------------------------------------------------------------------
void bullet_setRed(UserTypeBase* object, float value)
{
	Bullet* b = static_cast<Bullet*>(object);
	b->red = value;
}
// ----------------------------------------------------------------------------
float bullet_getRed(UserTypeBase* object)
{
	Bullet* b = static_cast<Bullet*>(object);
	return b->red;
}
// ----------------------------------------------------------------------------
void bullet_setGreen(UserTypeBase* object, float value)
{
	Bullet* b = static_cast<Bullet*>(object);
	b->green = value;
}
// ----------------------------------------------------------------------------
float bullet_getGreen(UserTypeBase* object)
{
	Bullet* b = static_cast<Bullet*>(object);
	return b->green;
}
// ----------------------------------------------------------------------------
void bullet_setBlue(UserTypeBase* object, float value)
{
	Bullet* b = static_cast<Bullet*>(object);
	b->blue = value;
}
// ----------------------------------------------------------------------------
float bullet_getBlue(UserTypeBase* object)
{
	Bullet* b = static_cast<Bullet*>(object);
	return b->blue;
}
// ----------------------------------------------------------------------------
void bullet_setAlpha(UserTypeBase* object, float value)
{
	Bullet* b = static_cast<Bullet*>(object);
	b->alpha = value;
}
// ----------------------------------------------------------------------------
float bullet_getAlpha(UserTypeBase* object)
{
	Bullet* b = static_cast<Bullet*>(object);
	return b->alpha;
}
// ----------------------------------------------------------------------------

}